package com.leyou.search.controller;

import com.leyou.search.service.SearchService;
import com.leyou.search.utils.SearchRequest;
import com.leyou.search.utils.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: taft
 * @Date: 2018-12-26 10:03
 */
@RestController
public class SearchController {

    @Autowired
    private SearchService searchService;


    @PostMapping("page")
    public ResponseEntity<SearchResult>  xxx(@RequestBody SearchRequest searchRequest){

       SearchResult searchResult =  this.searchService.xxx(searchRequest);

        if (searchResult != null && null!=searchResult.getItems() && 0!= searchResult.getItems().size()) {
            return ResponseEntity.ok(searchResult);
        }

        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();

    }
}
